<?php

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\service\GoodsDetail;
use Biz\model\GoodsBasicInfo;

$goods_id = 0;


$goodsinfo = GoodsBasicInfo::get('*', [
	'goods_id[>]' => $goods_id,
	'status' => [
		GoodsBasicInfo::STATUS_ONLINE,
		GoodsBasicInfo::STATUS_PASSED,
		GoodsBasicInfo::STATUS_OFFLINE,
		GoodsBasicInfo::STATUS_ADM_OFFLINE,
		GoodsBasicInfo::STATUS_WAIT_AUDIT,

	]
]);
$goods_id = $goodsinfo['goods_id'];

$results = [
	[
		'priceRange' => [
			0,
			99
		],
		'goods_number' => 0
	],
	[
		'priceRange' => [
			100,
			199
		],
		'goods_number' => 0
	],
	[
		'priceRange' => [
			200,
			299
		],
		'goods_number' => 0
	],
	[
		'priceRange' => [
			300,
			399
		],
		'goods_number' => 0
	],
	[
		'priceRange' => [
			400,
			499
		],
		'goods_number' => 0
	]
];

$templInfos = [];

while($goodsinfo){

	$goodsDetail = GoodsDetail::formatBasicInfos([$goods_id])[$goods_id];
	$min_price = $goodsDetail['min_price'];

	$templ_id = $goodsDetail['shipping_info']['templ_id'];

	if (!isset($templInfos[$templ_id])) {
		$templInfos[$templ_id] = \Biz\model\ShippingTemplAttr::select("*", [
			'templ_id' => $templ_id,
			'is_default' => 1,
			'base_price' => '0.00',
			'base' => 0,
			'status' => 1,
		]);
	}


	if ($templInfos[$templ_id]) {
		foreach ($results as &$result) {
			if ($result['priceRange'][0] <= $min_price && $result['priceRange'][1] >= $min_price) {
				$result['goods_number']++;
				var_dump($result);

			}
		}
	}

	$goodsinfo = GoodsBasicInfo::get('*', [
		'goods_id[>]' => $goods_id,
		'status' => [
			GoodsBasicInfo::STATUS_ONLINE,
			GoodsBasicInfo::STATUS_PASSED,
			GoodsBasicInfo::STATUS_OFFLINE,
			GoodsBasicInfo::STATUS_ADM_OFFLINE,
			GoodsBasicInfo::STATUS_WAIT_AUDIT,

		]
	]);
	$goods_id = $goodsinfo['goods_id'];
}

echo json_encode($results, JSON_UNESCAPED_UNICODE);
